/*
 * @Author: fhw
 * @Date: 2022-04-13 16:12:21
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-02-01 10:08:23
 * @Description:
 */
import { defineComponent, KeepAlive, reactive, watch } from 'vue'
import { RouterView, useRoute } from 'vue-router'
import zhCN from 'ant-design-vue/lib/locale/zh_CN'
import { ConfigProvider } from 'ant-design-vue'
export default defineComponent({
	name: 'App',
	render() {
		const cacheView = reactive({
			includeList: [] as string[],
		})
		const route = useRoute()
		watch(
			() => route,
			(newVal) => {
				if (newVal.meta.keepAlive && cacheView.includeList.indexOf(newVal.name as string) === -1) {
					cacheView.includeList.push(newVal.name as string)
				}
			},
			{ deep: true }
		) // 开启深度监听
		return (
			<ConfigProvider locale={zhCN}>
				<RouterView
					v-slots={{
						default: (scope: { Component: any }) => {
							return <KeepAlive include={cacheView.includeList ?? []}>{scope.Component}</KeepAlive>
						},
					}}
				></RouterView>
			</ConfigProvider>
		)
	},
})
